package com.lanou.controller;

import com.google.gson.Gson;
import com.lanou.service.SelectService;
import com.lanou.utils.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "BookAndCateServlet",urlPatterns = "/bookandcate")
public class BookAndCateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
    private SelectService selectService = new SelectService();
    //显示图书
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int bid = Integer.parseInt(String.valueOf(session.getAttribute("bid")));
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        AjaxResult ar = selectService.selectBookAndCate(bid);

        out.write(new Gson().toJson(ar));
        out.close();
    }
}
